// puplic functions 
$(document).ready(function() {
    $('.search input[type=text]').focus(function(){
				if($(this).val() == 'Search...' ){
					$(this).val('');
				}	
			});
	$('.search input[type=text]').blur(function(){
				if($(this).val() == '' ){
					$(this).val('Search...');
				}
			});
			
			
	

// appends 
	$('.top-bar ul li').append( $( "<span class='arrow'></span>" ) );
	$('.inner-side-column h3').append( $( "<span class='icon'></span>" ) );
	$('.side_list li').prepend( $( "<span class='icon'></span>" ) );
	$('.not_found li').prepend( $( "<span class='icon'></span>" ) );
	$('.sitemap li li').prepend( $( "<span class='icon'></span>" ) );
	$('.sitemap li li li').prepend( $( "<span class='icon'></span>" ) );
	$('.inner-side-column h4').append( $( "<span class='icon'>&#155;</span>" ) ); 
	$(".home-content .left-column .news li a").before("<span class='arrow'>&#187;</span>");
	$(".back-btn").append($( "<span class='icon'></span>" ));
	
	
	$( ".to-top" ).append( $( "<span class='icon'></span>" ) );
	$( ".to-top" ).wrapInner( "<span class='text'></span>" );
	
	$(".policies-list li, .list-links li").append($( "<span class='icon'></span>" ));
	$('.hospital_board li:odd').css('float', 'right');
	$('.patient-block:first, .staff-block:first').css('border-top', '0');
	$( ".bullet-list li, .staff-management li, .inner-main-column .news li" ).append( $( "<span class='bullet'></span>" ) );
	$( ".bullet-list li, .staff-management li, .inner-main-column .news li" ).wrapInner( "<span class='text'></span>" );
	$('.bullet-list > li > span > span.bullet, .staff-management > li > span > span.bullet, .inner-main-column .news > li > span > span.bullet, .to-top > span > span.icon ').each(function() {
		$(this).parent().before(this);
	});
	// height Adjust
	
	
		/*var height = $('.inner-content').height();
		$('.inner-main-column').height(height);
		$('.inner-side-column').height(height);*/
		
		
		var leftHeight = $('.inner-main-column').height();
	var rightHeight = $('.inner-side-column').height();
	 // console.log(calHeight+'|||||'+newsHeight);
	if (leftHeight > rightHeight) {
		$('.inner-side-column').height(leftHeight);
	}
	else if(leftHeight < rightHeight) {
		$('.inner-main-column').height(rightHeight);
	}
		
		
		
	
	$(".footer-menu li:last").css("padding-right", "0");
	/*$('.inner-main-column p:has(img)').each(function() {
		var x = $('.inner-content p img').height();
		console.log(x);
		var y = $(this).height();
		console.log(y);
		if (y > x) {
			$('.inner-content p img').css('margin-bottom', '30px');
		}
	});*/
	
	// tabs * ------------------------------------
	$(".tab-content").hide();
	$("ul#tabs li:first").addClass("active");
	$(".tab-content:first").show();
	$("ul#tabs li").click(function() {
	$("ul#tabs li").removeClass("active");
	$(this).addClass("active")
	$(".tab-content").hide();
	var activeTab = $(this).find("a").attr("href");
	$(activeTab).fadeIn();
	return false;
	});
	
	// to top 
	$('.to-top').click(function(){
				$('html, body').animate({
					scrollTop: $(".inner-content h2").offset().top
				}, 700);
			});
	// table 
	$('.table tr:odd td').css('background', '#f2f2f2');
	/* subString 
	----------------------------------------------*/
	$('.welcome-message p').each(function() {
		var $this = $(this);
		$this.text( $this.text().slice(0, 510) + ' ...');
	});
	
	$('.home_slider .slider-details p').each(function() {
		var $this = $(this);
		$this.text( $this.text().slice(0, 197) + ' ...');
	});
	
	$('.tab-data .data p').each(function() {
		var $this = $(this);
		$this.text( $this.text().slice(0, 200) + ' ...');
	});
	
	$('.home-content .right-column .ad p').each(function() {
		var $this = $(this);
		$this.text( $this.text().slice(0, 120) + ' ...');
	});
	
	$('.side-block p').each(function() {
		var $this = $(this);
		$this.text( $this.text().slice(0, 120) + ' ...');
	});
	
	$('.inner-content .inner-main-column .landing-list li p').each(function() {
		var $this = $(this);
		$this.text( $this.text().slice(0, 350) + ' ...');
	});
	
	$('.news li a').each(function() {
		var $this = $(this);
		$this.text( $this.text().slice(0, 200) + ' ...');
	});
	
	$('.inner-content .inner-main-column .search-results li p').each(function() {
		var $this = $(this);
		$this.text( $this.text().slice(0, 250) + ' ...');
	});
	
	$('.hospital_board li .details-area .details p').each(function() {
		var $this = $(this);
		$this.text( $this.text().slice(0, 120) + ' ...');
	});
	
	// 
	

});
$(window).load(function(){
      
	  // MAIN SLIDER 
	  
	  $('.main_slider').flexslider({
        animation: "fade",
		pausePlay: true,               //Boolean: Create pause/play dynamic element
		pauseText: '',             //String: Set the text for the "pause" pausePlay item
		playText: '',
		prevText: "",           //String: Set the text for the "previous" directionNav item
		nextText: "",
		controlNav: false,
		slideshowSpeed: 4000,
		animationSpeed: 1000,
        start: function(slider){
          $('body').removeClass('loading');
        }
      });
	  // HOME SLIDER
	  var total = $('.home_slider li').length;
	  $('span.total').text(' / ' + total);
	  
	  $('.home_slider').flexslider({
        animation: "slide",
		pausePlay: true,               //Boolean: Create pause/play dynamic element
		pauseText: '',             //String: Set the text for the "pause" pausePlay item
		playText: '',
		prevText: "",           //String: Set the text for the "previous" directionNav item
		nextText: "",
		controlNav: false,
		slideshow: true,
		slideshowSpeed: 4000,
		animationSpeed: 500,
        start: function(slider){
          $('span.index').text(slider.count);
   	 	$('span.index').text(slider.currentSlide);
    	$('span.index').text(function(i,txt) { return parseInt(txt, 10) + 1; } );
        },
  		after: function(slider) {
    	$('span.index').text(slider.currentSlide);
    	$('span.index').text(function(i,txt) { return parseInt(txt, 10) + 1; });
		}
      });
	  
	  // Home carousel
	  $('.parner_slider').flexslider({
        animation: "slide",
        animationLoop: true,
        itemWidth: 120,
        itemMargin: 20,
		slideshow: false,
        pausePlay: false,
		controlNav: false,
		nextText: "",
		prevText: "",
        start: function(slider){
          $('body').removeClass('loading');
        }
      });
	  
    });
	
	
	/* ================================================
		Calendar & news 
   ================================================ */
$(window).load(function() {
		// top 
        $('.news-block:even p').each(function(index, element) {
            if ( $(this).children('i').length > 0 ) {
				$(this).children('i').css({float: 'right', marginRight: '0', marginLeft: '24px'});
				
		}
		else{
			$(this).children('span').css('width', 'auto');
		}
        });
		
		// bottom 
		$('.news-block:odd p').each(function(index, element) {
			if ( $(this).children('i').length > 0 ) {
				
				$(this).children('span').css({width: '435px'});
		}
		else{
			
			//$('.news-block:odd h4').css({float: 'left', width: 'auto'});
			$(this).children('span').css({width: 'auto'});
		}
		});
		
		$('.news-block p').each(function(){
			var y = $(this).width();
			var x = $(this).children('i').children('img').width()+26;
			$(this).children('.news-block p i + span').width(y-x);
			$(this).children('i').width($(this).children('i').children('img').width()+2);
			
			// console.log("image width" +'\n' + x);
			
			// console.log("paragraph" +'\n' + y);
		});
		
		$('.list-fake span.square').html('&#9642;');
		
    });
